/// <reference path="/scripts/jquery-1.8.0-vsdoc.js" />

$(function ()
{
    var $filmPage = $("#filmPage");
    var $thumbPanel = $("#thumbnails");

    // Make thumbs draggable.
    $("li", $thumbPanel).draggable({
        revert: "invalid",
        containment: "document",
        helper: "clone",
        cursor: "move"
    });

    // Make file page droppable and tell it to accept thumbs.
    $(".frame", $filmPage).droppable({
        accept: "#thumbnails li",
        activeClass: "flying",
        drop: function (event, ui)
        {
            deleteImage(this, ui.draggable);
        }
    });

    function deleteImage($target, $item)
    {
        $item.fadeOut(50, function ()
        {
            $($item).children("img").appendTo($target).fadeIn(100);
            $($target).addClass("filled");
            $($item).remove();
        });
    }
});